package com.yanqu.road.server.manger.activity.recycle;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.ActivityItemRecycleData;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.player.UserBagItem;
import com.yanqu.road.logic.activity.horserun.HorseRunConfig;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.horserun.HorseRunMgr;

import java.util.ArrayList;
import java.util.List;

public class HorseRunRecycleStrategy extends AbstractItemRecycleStrategy{
    @Override
    public void markNeedRecycleItem() {
        HorseRunConfig config = HorseRunMgr.getConfig();
        if (config != null) {
            ActivityInfo activityInfo = config.getActivityInfo();
            long recycleTime = activityInfo.getEndTime() * 1000L + 600 * 1000;
            //体力道具
            int openAdventureItem = config.getOpenAdventureItem();
            //都清空
            ActivityItemRecycleMgr.addRecycleItemData(openAdventureItem, activityType, 2, recycleTime, new ArrayList<>());
            List<Integer> needRecycleItemList = config.getNeedRecycleItemList();
            if (needRecycleItemList != null) {
                for(int itemId : needRecycleItemList) {
                    //都清空
                    ActivityItemRecycleMgr.addRecycleItemData(itemId, activityType, 2, recycleTime, new ArrayList<>());
                }
            }
        }
    }

    @Override
    protected void initActivityType() {
        activityType = eActivityType.HorseRun.getValue();
    }

    @Override
    protected void doRecycle(long userId, ActivityItemRecycleData data) {
        if (data.getRecycleType() == 2) {
            int itemId = data.getItemId();
            UserBagItem userBagItem = getUserBagItem(userId, itemId);
            if (userBagItem != null && userBagItem.getNum() > 0) {
                removeItem(userBagItem);
            }
        }
    }

    @Override
    public boolean isActivityRunning() {
        HorseRunConfig config = HorseRunMgr.getConfig();
        return config != null && ActivityMgr.activityInTime(config.getActivityInfo());

    }
}
